﻿<%@ include file="/WEB-INF/work/start.jspf"%>
<html>
<head>
<%@ include file="/WEB-INF/jspf/meta.jspf"%>
<title>日报列表</title>
<%@ include file="/WEB-INF/work/css.jspf"%>
</head>
<body>
<input type="datetime" name="start-date" placeholder="开始日期" readonly="readonly" />
<fmt:parseNumber var="project" integerOnly="true" type="number" value="${param.project}" />
<fmt:parseNumber var="daily" integerOnly="true" type="number" value="${param.daily}" />
<c:set var="aaa" value="assigned-to" />
<fmt:parseNumber var="assignedTo" integerOnly="true" type="number" value="${param[aaa]}" />
<c:set var="status" value="${param.status}" />
<select id="project">
	<sql:query var="items" dataSource="${work}">
		select * from simpletask_project order by id desc
	</sql:query>
	<option value="">所有</option>
	<c:forEach var="item" items="${items.rows}">
		<c:choose>
			<c:when test="${item.id==project}">
				<option value="${item.id}" selected="selected">${item.name}</option>
			</c:when>
			<c:otherwise>
				<option value="${item.id}">${item.name}</option>
			</c:otherwise>
		</c:choose>
	</c:forEach>
</select>
<select id="status">
	<%
		Map<String,String> allStatus=new LinkedHashMap<String,String>();
		allStatus.put("plan","计划");
		allStatus.put("uncompleted","未完成");
		allStatus.put("done","完成");
		allStatus.put("defer","推迟");
		
		request.setAttribute("allStatus",allStatus);
	%>
	<option value="">所有</option>
	<c:forEach var="item" items="${allStatus}">
		<c:choose>
			<c:when test="${item.key==status}">
				<option value="${item.key}" selected="selected">${item.value}</option>
			</c:when>
			<c:otherwise>
				<option value="${item.key}">${item.value}</option>
			</c:otherwise>
		</c:choose>
	</c:forEach>
</select>
<select id="daily">
<option value="">所有</option>
	<sql:query var="items" dataSource="${work}">
		select id,title from workdaily_taskdaily order by daily_at desc
	</sql:query>
	<c:forEach var="item" items="${items.rows}">
		<c:choose>
			<c:when test="${item.id==daily}">
				<option value="${item.id}" selected="selected">${item.title}</option>
			</c:when>
			<c:otherwise>
				<option value="${item.id}">${item.title}</option>
			</c:otherwise>
		</c:choose>
	</c:forEach>	
</select>
<select id="assigned-to">
<option value="">所有</option>
	<sql:query var="items" dataSource="${work}">
		select distinct b.id,b.username  as name from workdaily_task a inner join auth_user b on b.id=a.assigned_to_id
	</sql:query>
	<c:forEach var="item" items="${items.rows}">
		<c:choose>
			<c:when test="${item.id==assignedTo}">
				<option value="${item.id}" selected="selected">${item.name}</option>
			</c:when>
			<c:otherwise>
				<option value="${item.id}">${item.name}</option>
			</c:otherwise>
		</c:choose>
	</c:forEach>
</select>
<table class="pure-table ui table pure-table-bordered" id="task-list" style="width:100%">
	<thead>
		<tr>
			<th>Daily</th>
			<th>项目</th>
			<th>内容</th>
			<th>任务日期</th>
			<!--<th>创建时间</th>-->
			<th>状态</th>
			<th>分配给</th>
		</tr>
	</thead>
	<tbody>
		<sql:query var="items" dataSource="${ work }">
select a.*
	,b.title as daily
	,e.name as project_name
	,d.username as assigned_to
from workdaily_task a
INNER JOIN workdaily_taskdaily b on a.daily_id = b.id
inner join simpletask_project e on e.id=a.project_id
inner join auth_user d on d.id=a.assigned_to_id
where 1=1 
		<c:if test="${! empty status}">
			and a.status=?
		</c:if>
		<c:if test="${! empty project}">
			and a.project_id=?
		</c:if>
		<c:if test="${! empty daily}">
			and a.daily_id=?
		</c:if>	
		<c:if test="${! empty assignedTo}">
			and a.assigned_to_id=?
		</c:if>	
order by b.daily_at desc,a.task_at desc
		<c:if test="${! empty status}">
		<sql:param>${status}</sql:param>
		</c:if>
		<c:if test="${! empty project}">
			<sql:param value="${project}"></sql:param>
		</c:if>
		<c:if test="${! empty daily}">
			<sql:param value="${daily}"></sql:param>
		</c:if>
		<c:if test="${! empty assignedTo}">
			<sql:param value="${assignedTo}"></sql:param>
		</c:if>	
		</sql:query>
		<c:forEach var="item" items="${items.rows}" varStatus="status">
			<tr class="task-${item.status}">
			<td>${item.daily}</td>
			<td>${item.project_name}</td>
			<td>${item.content}</td>
			<td><fmt:formatDate value="${item.task_at}" pattern="MM-dd" /></td>
			<!--<td>${item.created_at}</td>-->
			<td>${allStatus[item.status]}</td>
			<td>${item.assigned_to}</td>
			</tr>
		</c:forEach>
	</tbody>
</table>
<%@ include file="/WEB-INF/jspf/js.jspf"%>
<script type="text/javascript">
 var queryString = {},
	 url='<%=request.getRequestURI()%>';
if (location.search) {
   var qa = location.search.substring(1).split('&');
   for (var i = 0, t = qa.length; i < t; i++) {
	   var item=qa[i].split('=');
	   queryString[item[0]] = item[1]||'';
   }
}

$("select").change(function(){
	var self=$(this),
		q={};
	q[self.attr('id')]=self.val();
	location.href=url+'?'+$.param($.extend(queryString,q));
});
</script>
</body>
</html>